// import './vconsole'
import '@/bootstrap'
import Vue from 'vue'
import { detect } from '@/utils'
import FastClick from 'fastclick'
import router from '@/router'
import store from '@/store'
import i18n from '@/lang'
import '@/mixins'
import App from '@/App'
import * as filters from '@/filters' // global filters

import '@/icons'
import '@/errorLog'

import '@/styles/index.less' // global styles

/*
在电脑端将mouse改成touch事件d, 让用户可以使用电脑微信发布信息
*/
import '@vant/touch-emulator';

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

/*
  bug fix: 修复ios11以后增加passive消极模式，导致的fastclick功能失效，从而需要多次点击input才能focus的bug
*/
FastClick.prototype.focus = function(targetElement) {
  var length

  // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
  if (detect() === 'ios' && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
    length = targetElement.value.length
    targetElement.setSelectionRange(length, length)
    /*修复bug ios 11.3不弹出键盘，这里加上聚焦代码，让其强制聚焦弹出键盘*/
    targetElement.focus()
  } else {
    targetElement.focus()
  }
}

/**
 *
 * 重写fastclick的needsClick函数，因为video播放暂停按钮组件和fastclick的冲突
 */
FastClick.prototype.needsClick = function(target) {
  switch (target.nodeName.toLowerCase()) {

  // Don't send a synthetic click to disabled inputs (issue #62)
  case 'button':
  case 'select':
  case 'textarea':
    if (target.disabled) {
      return true;
    }

    break;
  case 'input':

    // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
    if ((deviceIsIOS && target.type === 'file') || target.disabled) {
      return true;
    }

    break;
  case 'label':
  case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
  case 'video':
    return true;
  }

  return (/\bneedsclick\b/).test(target.className) || (/\bvjs/).test(target.className);
};

FastClick.attach(document.body)

Vue.config.productionTip = false

Vue.config.ignoredElements = ['wx-open-audio', 'wx-open-subscribe', 'wx-open-launch-weapp']

// 设置手机型号：ios、android
store.commit('SET_DEVICE', detect())
// 设置七牛域名
store.commit('SET_QINIU_DOMAIN', process.env.QINIU_DOMAIN)

import { wechatGetOpenid, reloadWithoutCode } from '@/wxLogin'
// 先登登获取openid获取才执行业务逻辑
wechatGetOpenid()
.then((openid) => {

  store.commit('SET_OPENID', openid)

  new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
  }).$mount('#app-box')
})
.catch(err => {

  console.error('wechat get openid error', err)
  
  Vue.$vux.alert.show({
    content: i18n.t('loginFailed', [err]),
    buttonText: i18n.t("tryAgainByClick"),
    onHide: () => {
      reloadWithoutCode()
    }
  })
})




